package com.blue.spring.redis;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.data.redis.core.RedisTemplate;

/**
 * RedisHttpSession 的HttpServletRequestWrapper
 * 
 * @author zhengj
 * @since 2016年5月17日 1.0
 */
public class RedisHttpServletRequestWrapper extends HttpServletRequestWrapper
{
	private HttpServletResponse response;
	private RedisTemplate<String, Object> redisTemplate;
	private String tokenName;
	private int expire;
	private String key;
	
	public RedisHttpServletRequestWrapper(HttpServletRequest request, HttpServletResponse response,
			RedisTemplate<String, Object> redisTemplate, String tokenName, int expire, String key)
	{
		super(request);
		this.response = response;
		this.redisTemplate = redisTemplate;
		this.tokenName = tokenName;
		this.expire = expire;
		this.key = key;
	}

	@Override
	public HttpSession getSession()
	{
		return getSession(true);
	}

	@Override
	public HttpSession getSession(boolean create)
	{
		HttpSession session = new RedisHttpSession(this.getServletContext(), this, response, redisTemplate, tokenName, expire, key);
		return session;
	}
	
}
